home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2053 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: info.uah.edu!oreo!gbacon
  2. From: gbacon@oreo (Greg Bacon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: question on pass-by-reference
  5. Date: 18 Jan 1996 19:53:26 GMT
  6. Organization: The University of Alabama in Huntsville
  7. Message-ID: <4dm8fm$bsi@info.uah.edu>
  8. References: <4dha4j$4qg@shrike.depaul.edu>
  9. Reply-To: gbacon@CS.UAH.Edu
  10. NNTP-Posting-Host: oreo.aspire.cs.uah.edu
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Kazuki Murakami (kmurakam@shrike.depaul.edu) wrote:
  14.  
  15. : I have a question on pass-by-reference.
  16. : Here is a problem, I want to set array of unsigned short number to be
  17. : all 0 using a function.  here is what set looks like:
  18.  
  19. :     typedef unsigned short USHORT;
  20. :     typedef  USHORT SET[32];
  21.  
  22. :     void setInit (SET *s)
  23. :     {
  24. :         int i;
  25.  
  26. :         for (i=0; i<32; i++)
  27. :         {
  28. :             *s[i] = 0;
  29. :         }
  30. :     }
  31.  
  32. : here is the calling function.
  33. :         setInit(&set1);  setInit(&set2);
  34.  
  35. : I think there is somthing wrong in "setInit" function but I cannot
  36. : seem to figure out what that is.  If somebody can figure out what
  37. : that is or some other way of initializing "SET s" please give me a
  38. : e-mail.
  39.  
  40. : Thank you
  41. :         
  42. : Kazuki Murakami
  43.  
  44. OK.. you want your setInit() function to look like this:
  45.  
  46. void setInit(USHORT *set)
  47. {
  48.    int i;
  49.  
  50.    for(i = 0; i < 32; i++)
  51.       *(set + i) = 0;
  52. }
  53.  
  54. and call it like this..
  55.  
  56. {
  57.    SET set1, set2;
  58.  
  59.    setInit(set1);
  60.    setInit(set2);
  61.  
  62. Neat how that whole equivalence of pointers and arrays works in C, ain't
  63. it? :)
  64.  
  65. Greg
  66. --
  67. Greg Bacon <gbacon@cs.uah.edu>
  68. University of Alabama in Huntsville
  69. CS Department Systems Support Team
  70.